from django.shortcuts import render
from django.contrib.auth.models import Permission
from rest_framework import permissions, viewsets, status, views, generics, mixins

from .models import *
from .serializers import *
from .permission import IsStaff


class PermissionViewSet(viewsets.ModelViewSet):
    queryset = Permission.objects.all()
    serializer_class = PermissionSerializer


class GroupViewSet(viewsets.ModelViewSet):
    queryset = Group.objects.all()
    serializer_class = GroupSerializer


class UserViewSet(viewsets.ModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer
    # 所有人都可以增删改自己的
    # 查的时候需要是管理员才可以，不是所有人都能看的
    permission_classes = [permissions.IsAuthenticatedOrReadOnly, IsStaff]
    # authentication_classes = [MyAuthentication]
